#include "InitMessage.hh"
#include "GameList.hh"
#include "GetGameList.hh"
#include "JoinGame.hh"
#include "NewGame.hh"
#include "PlayerJoined.hh"
#include "XmlServerThread.hh"
#include "../Exception.hh"

using namespace Network;

spInitMessage InitMessage::construct(QDomElement const& message) {
    QDomElement inner = message.firstChildElement();
    QString tagName = inner.tagName();

    if (tagName == "get_game_list")
        return GetGameList::construct(inner);

    if (tagName == "game_list")
        return GameList::construct(inner);

    if (tagName == "join_game")
        return JoinGame::construct(inner);

    if (tagName == "new_game")
        return NewGame::construct(inner);

    if (tagName == "player_joined")
        return PlayerJoined::construct(inner);

    throw NonFatalProtocolError("init invalid");
}
